package leecode

func maxOperations(nums []int, k int) int {
	hashMap := make(map[int]int)
	for i := 0; i < len(nums); i++ {
		hashMap[nums[i]]++
	}
	var result int
	for i := 0; i < len(nums); i++ {
		if _, ok := hashMap[k-nums[i]]; ok && hashMap[nums[i]] > 0 {
			hashMap[nums[i]]--
			hashMap[k-nums[i]]--
			if hashMap[k-nums[i]] < 0 {
				continue
			}
			result++
		}
	}
	return result
}
